package com.shenzhen.horselive.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.databinding.DialogPulicRedpackageBinding;

public class GiveRedpackageDialog extends Dialog {
    DialogPulicRedpackageBinding   binding;
    private  OnItemClick   onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public GiveRedpackageDialog(@NonNull Context context) {
        super(context, R.style.CommonDialog);
        binding = DialogPulicRedpackageBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        binding.tvRed.setOnClickListener(onClickListener);
        binding.tvCoupon.setOnClickListener(onClickListener);
        binding.tvApp.setOnClickListener(onClickListener);



    }


    private View.OnClickListener  onClickListener =new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
            switch (v.getId())
            {
                case R.id.tv_red:
                    if (onItemClick!=null)
                        onItemClick.onClick(1);
                    break;
                case R.id.tv_coupon:
                    if (onItemClick!=null)
                        onItemClick.onClick(2);
                    break;
                case R.id.tv_app:
                    if (onItemClick!=null)
                        onItemClick.onClick(3);
                    break;
            }
        }
    };






    public GiveRedpackageDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected GiveRedpackageDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }


    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width= ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height= ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(layoutParams);
    }



    public interface OnItemClick{
        void  onClick(int positon);
    }

}
